home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
oper_sys
/
emerald
/
emrldsys.lha
/
ErrCodes
/
errMsgs.c
Wrap
C/C++ Source or Header
|
1990-08-17
|
4KB
|
176 lines
/* File: /u1/oystr/ErrCodes/errMsgs.c Date: 23-Nov-1982 */
/*
* $Header$
* INTERFACE: These routines provide and interface to the Eden
* Message Retrieval system. This turkey is a direct
* clone of the VMS $GETMSG/$PUTMSG facility.
*
* FUNCTION: Access the error message database and string table.
*
* IMPORTS: errMsg.h, dbm(3X) (multichannel) functions.
*
* EXPORTS: GetEdenMsg, PutEdenMsg, DisplayEdenMsg
*
* DESIGN: See "Eden Error Message Retrieval System", J. Sanislo,
* TBS
*
* $Log$
* 23-Nov-1982: Initial implementation. J. Sanislo.
* 24-Jan-1983: Modified for multiple channel dbm. J. Sanislo.
*/
#include "errMsgs.h"
#include <stdio.h>
#include "system.h"
#undef NULL
#include <dbm.h>
#define cdbminit(xxx) dbminit(xxx)
#define cfetch(fChannel, fKey) fetch(fKey)
#define cstore(fChannel, fKey, fContent) store(fKey, fContent)
#define MAXMSGLEN 128
/*
* One file does it all. The strings are kept in EdenErrStr.
* The database files EdenErrStr.dir and EdenErrStr.pag maintain
* (key, content) pairs of (errorcode value, offset in string file).
*/
char efilname[] = "/usr/projects/emerald/ErrCodes/EdenErrStr";
int efil = -1; /* >= 0 => stringfile already open */
char NoMsg[] = "NONAME-F: No message for code: %8.8x";
char NoText[] = "No text for code: %8.8x";
char ECSuffix[] = "WSFIKM";
int dfil = -1;
/*ARGSUSED*/
int GetEdenMsg(fEC,fBufSize,fBuffer, fFlags)
int fEC;
int fBufSize;
char fBuffer[];
int fFlags;
{
#if defined(NODISK) || defined(xkernel)
return(EMRK_AccStr);
#else
datum key, content;
int offset;
char buf[MAXMSGLEN];
int localint;
int headlen;
if (efil < 0) {
efil = open(efilname,0);
if (efil < 0) {
perror(efilname);
return(EMRK_AccStr);
}
}
if (dfil < 0 ) {
dfil = cdbminit(efilname);
if (dfil < 0) {
perror(efilname);
return(EMRK_InitDB);
}
}
/*
* Get the abbreviation associated with the facility code.
*/
localint = ( (unsigned) fEC ) >> 16;
key.dsize = 4;
key.dptr = (char *) &localint;
content = cfetch(dfil, key);
if (content.dptr == NULL) {
sprintf(buf,NoMsg,fEC);
if ( (strlen(buf)+1) > fBufSize)
buf[fBufSize-2] = '\0';
(void) strcpy(fBuffer,buf);
return(EMRF_NoMsg);
}
/* return( makeNullMsg(fEC,fBufSize,fBuffer) ); */
offset = * (int *) content.dptr;
if (lseek(efil, (long) offset, 0) < 0)
return(EMRK_AccStr);
if (read(efil, buf, MAXMSGLEN) <= 0)
return(EMRK_AccStr);
(void) strcat(buf,"- : ");
headlen = strlen(buf);
localint = fEC;
key.dsize = 4;
key.dptr = (char *) &localint;
content = cfetch(dfil, key);
if (content.dptr == NULL) {
buf[headlen-3] = 'F';
sprintf(&buf[headlen], NoText, fEC);
if ( (strlen(buf)+1) > fBufSize)
buf[fBufSize-2] = '\0';
(void) strcpy(fBuffer,buf);
return(EMRF_NoMsg);
}
/* return(makeNullMsg(fEC,fBufSize,fBuffer)); */
offset = * (int *) content.dptr;
if (lseek(efil, (long) offset, 0) < 0)
return(EMRK_AccStr);
if (read(efil, &buf[headlen], MAXMSGLEN - headlen) <= 0)
return(EMRK_AccStr);
buf[headlen-3] = ECSuffix[fEC % MODULUS];
if ( (strlen(buf)+1) <= fBufSize) {
(void) strcpy(fBuffer,buf);
return(EMRS_Success);
}
else {
buf[fBufSize-2] = '\0';
(void) strcpy(fBuffer,buf);
return(EMRW_MsgTrunc);
}
#endif
} /* End of GetEdenMsg */
/*ARGSUSED*/
int PutEdenMsg(fEC, fOut, fArgv)
int fEC;
FILE *fOut;
char *fArgv[];
{
char buf[MAXMSGLEN];
int status;
#ifndef xkernel
FILE *outfile;
#endif
status = GetEdenMsg(fEC,MAXMSGLEN,buf,0);
#ifdef BSD
if ( fOut != 0 ) outfile = fOut;
else outfile = stderr;
#endif
if ( mNOERROR(status) || (status == EMRF_NoMsg) )
#ifdef BSD
fprintf(outfile,"%s\n",buf);
#else
printf("%s\n",buf);
#endif
return(status);
}
int DisplayEdenMsg(fString)
char fString[];
{
#ifdef BSD
fprintf(stderr,"%s\n",fString);
#else
printf("%s\n",fString);
#endif
return(EMRS_Success);
}